package com.aviation.sell_ticket.mapper;

import com.aviation.sell_ticket.pojo.Aviation_order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {


    /**
     * 添加新的订单
     * @param order 订单数据
     * @return Integer
     */
    @Insert("insert into aviation_order(order_id,price,generation_time,payment,user_id,mailbox,departure,destination) values(#{order.order_id},#{order.price},#{order.generation_time},#{order.payment},#{order.user_id},#{order.mailbox},#{order.departure},#{order.destination})")
    public Integer generatedOrder(@Param("order") Aviation_order order);

    /**
     * 修改订单状态
     * @param price 价格
     * @param orderId 订单id
     * @return Integer
     */
    @Update("update aviation_order set price=#{price} where order_id=#{orderId}")
    public Integer updateOrder(@Param("price")Double price,@Param("orderId") String orderId);

    @Select("select count(*) from aviation_order where order_id=#{orderId} and payment=0")
    public Integer verifyOrderStatus(@Param("orderId") String orderId);

    @Update("update aviation_order set payment=1 where order_id=#{orderId}")
    public Integer changeOrderStatus(@Param("orderId") String orderId);

    @Select("select order_id,price,generation_time,payment,mailbox,departure,destination from aviation_order where user_id=#{userId}")
    public List<Aviation_order> extractOrder(@Param("userId")String userId);

    @Select("select order_id,price,generation_time,payment,mailbox from aviation_order where user_id=#{userId} and order_id=#{orderId}")
    public Aviation_order singleOrder(@Param("userId")String userId,@Param("orderId")String orderId);


    @Update("update aviation_order set payment=2,time_payment=#{timestamp} where order_id=#{orderId} and price=#{total_amount}")
    public Integer orderStatusUpdate(@Param("orderId")String orderId,@Param("timestamp")String timestamp,@Param("total_amount")String total_amount);


    @Select("select * from aviation_order where order_id=#{orderId}")
    public Aviation_order verifyOrderStatusEntity(@Param("orderId") String orderId);


    @Update("update aviation_order set payment=3,refundId=#{refundId} where order_id=#{orderId}")
    public int orderRefund(@Param("refundId") String refundId,@Param("orderId") String orderId);

}
